library Wave7 initializer init requires LegacySystem

	globals
		private integer array           udg_Resupply
	endglobals
    private function HomeSearch takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit u2
        local player p = GetOwningPlayer(u)
        local integer i = 1
        local real x
        local real y
        if GetPlayerController(p)!=MAP_CONTROL_USER or GetUnitAbilityLevel(u,'Aloc')>0 or GetUnitPointValue(u)==5 then
            set u = null
            return
        endif
        call DestroyTrigger(GetTriggeringTrigger())
        loop
            exitwhen (i>7) or (RectContainsCoords(udg_ConvoyPath[i],GetUnitX(u),GetUnitY(u)))
            set i=i+1
        endloop
        call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))-0.005)
        call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))-0.005)
        call PolledWait(1.)
        set i = GetConvertedPlayerId(GetOwningPlayer(u))
        if GetRandomInt(0,1)==1 then
            call FieldChat(u, 5.0, udg_Pcolors[i] + GetUnitName(u) + "|r : Found some survivors." )
        elseif GetRandomInt(0,1)==1 then
            call FieldChat(u, 5.0, udg_Pcolors[i] + GetUnitName(u) + "|r : Follow me, we need to get you out of here." )
        else
            call FieldChat(u, 5.0, udg_Pcolors[i] + GetUnitName(u) + "|r : Don't be afraid." )
        endif
        call PolledWait(0.5)
        set x = GetUnitX(u)
        set y = GetUnitY(u)
        call StartSound(gg_snd_Loading)
        if GetRandomInt(0,20)==1 and GetWidgetLife(udg_Boss)<=0.405 then
            set udg_Boss = CreateUnit(p,'nvl2',x,y,0.0)
        else
            set u2 = CreateUnit(p,'nvl2',x,y,0.0) //Male
            
            call RegisterUnitForAilmentChecks(u2)
        endif
        call PolledWait(0.5)
        call StartSound(gg_snd_Loading)
        set u2 = CreateUnit(p,'nvlw',x,y,0.0)
        call RegisterUnitForAilmentChecks(u2)
        call PolledWait(0.5)
        call StartSound(gg_snd_Loading)
        set u2 = CreateUnit(p,'nvlk',x,y,0.0)
        call RegisterUnitForAilmentChecks(u2)
        set udg_CiviliansAlive = udg_CiviliansAlive + 3
        set u = null
        set u2 = null
    endfunction
    

    private function Wave7c takes nothing returns nothing
        local integer i = 1
        set udg_CurrentWave = 7
        call GenericActions.execute()
        call LightningAmbience.execute()
        call PolledWait(3.0)
        call GeneralText(6.0, "|cffcd950cBattalion|r : Something strange is forming in your sector. Our science team calls it dark clouds, and it's blanketing the sky. You're going to lose visibility. Use your field lights. Over." )
        call PolledWait(7.)
        call LightningAmbience.execute() 
        call GeneralText(4.0, "|cffcd950cMarine|r : We weren't briefed on this. Anything else we need to know? Over." )
        call PolledWait(6.)
        call GeneralText(5.0, "|cffcd950cBattalion|r : It's probably not dangerous if that's what you're thinking. Everything's on a need to know basis. We don't know much about it now. Over." )
        call LightningAmbience.execute()
        call PolledWait(1.2)
        set udg_GlobalBoolean[1337] = true //Dark Clouds indicator. Used for Fire Mission accuracy
        call SetDayNightModels("","")
        if GetRandomInt(0,5)==1 then
            call RandomSpawn('u00O',1,2) //Leviathan
        else
            call RandomSpawn('n003',udg_Players,udg_Spawn) //Immortals
            call RandomSpawn('u004',1, GetRandomInt(1,2+udg_Spawn) ) //Wraith
            call StartSound(udg_Ambience[8])
            call RandomSpawn('nsw1',1,2+udg_Spawn) //Stalker
        endif
        call PolledWait(2.)
        call GeneralText(5.0, "|cffcd950cMarine|r : Shit. Probably? We have next to zero visibility. We're not moving anywhere until this clears up.. if it does. Out" )
        call PolledWait(4.)
        call MultiboardSetTitleText( udg_SquadStatus, "Dark Clouds present in Sector E" )
        call QuestSetDescription(udg_CurrentOrders, "Dark clouds are severely interfering with radio frequency and limiting visibility. We know that this strange cloud originated from Boston where the outbreak occured. It doesn't seem to have any effect that we are aware of, but don't take any chances. |n|nStay with your fire team and use artificial light sources to defend your perimeter." )
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5.0, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : It's shit dark. Stay with a light source." )
        call PolledWait(4.)
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5.0, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : My damn NVGs aren't working!" )
        call PolledWait(5.)
        call StartSound(udg_Ambience[1])
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : What's going on man!" )
        call PolledWait(5.)
        call StartSound(udg_Ambience[8])
        call PolledWait(10.0*udg_Pace)
        set udg_soundpath = "Sound\\Time\\DuskWolf.wav"
        call PlaySoundPath.execute()
        
        call PolledWait(25.0*udg_Pace)
        call SetProximitySpawnEnabled(true)
        //set udg_soundpath = "Sound\\Music\\mp3Music\\Undead3.mp3"
        //call PlaySoundPath.execute()
        if udg_Players>2 then
            call GeneralText(5.0, "|cffcd950cMarine|r : Stay sharp and stay close. We've evaced most of the civilian population. If anything's moving, it's probably Zack. Listen to the moans and let it rip. Any questions?" )
        endif
        call PolledWait(5.)
        call StartSound(udg_Ambience[8])
        call PolledWait(5.)
        if udg_Players>2 then
            call GeneralText(5.0, "|cffcd950cMarine #2|r : Sir, do you think Hooters girls would look better in white shorts than orange?" )
        endif
        call PolledWait(3.)
        call StartSound(udg_Ambience[2])
        call PolledWait(30.0*udg_Pace)
        call ExecuteRegisteredFunction("Wave8c")
        //call Wave8c.execute()
    endfunction

    private function Wave7a takes nothing returns nothing
        local integer i = 1
        local integer homes = 0
        local real x
        local real y
        local trigger t
        set udg_Boss = null
        set udg_CurrentWave = 7
        call GenericActions.execute()
        set udg_Visibility = 67
        call IntermissionRestore()
        set udg_Visibility = 65
        call IntermissionRestore()
        loop
            exitwhen i>8
            call RemoveRect(udg_ConvoyPath[i])
            set i = i+1
        endloop
        set udg_ConvoyPath[1] = gg_rct_Home1
        set udg_ConvoyPath[2] = gg_rct_Home2
        set udg_ConvoyPath[3] = gg_rct_Home3
        set udg_ConvoyPath[4] = gg_rct_Home4
        set udg_ConvoyPath[5] = gg_rct_Home5
        set udg_ConvoyPath[6] = gg_rct_Home6
        set udg_ConvoyPath[7] = gg_rct_Home7
        loop //6 and 7 are outlier homes. Intended effect.
            exitwhen homes > 3
            set i = 1
            loop
                exitwhen i > 7
                if GetRandomInt(1,3)==1 and udg_Resupply[i]!=1 and homes<4 then
                    set t = CreateTrigger()
                    call TriggerRegisterEnterRectSimple( t, udg_ConvoyPath[i] )
                    call TriggerRegisterLeaveRectSimple( t, udg_ConvoyPath[i] )
                    call TriggerAddAction( t, function HomeSearch )
                    set udg_Resupply[i] = 1
                    set homes = homes + 1
                endif
                set i = i + 1
            endloop
        endloop
        set t = null
       
        
        call SetImmortalSpawnEnabled(true)
        
       // call DestroyTrigger(gg_trg_Convoy_Exit)
        call RandomSpawn('u00L',4,IMinBJ(4,udg_Players)) //Blink
        call RandomSpawn('uabo',1,GetRandomInt(0,1)) //Flesh Composite
        call GeneralText(2.0, "|cffcd950cMarine|r : Turn on your NVGs. You won't see shit in this darkness." )
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(13),'n003',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'u000',2*udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(13),'n003',GetRandomInt(1,udg_Spawn))
        if udg_SquadXP>20000 then
            call RandomSpawn('n016',1,udg_Spawn) //Invi Worm
        endif
        call RandomSpawn('n002',1,GetRandomInt(1, udg_Spawn)) //Devourer
        if udg_SurveillanceComplete==5 then
            call GeneralText(5.0, "|cffcd950cBattalion|r : The Surveillance Sentries confirmed our suspicions. Zulus are everywhere." )
        endif
        set udg_Environment[1] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        call PolledWait(8.0*udg_Pace)
        set udg_Environment[2] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        set udg_Environment[3] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        call GeneralText(5.0, "|cffcd950cBattalion|r : Heartbeat sensors are still picking up lifesigns in Ravenholm. Head to the town and extract any survivors from their homes." )
        call PolledWait(8.)
        // Bats in town
        set udg_Environment[3] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        set udg_Environment[4] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        set udg_Environment[5] = CreateDestructable('B001',GetRandomReal(-1500.0,250.0),GetRandomReal(-775.0,1150.0),GetRandomReal(0.0,360.0),GetRandomReal(1.2,2.1),0)
        set udg_soundpath = "Units\\Undead\\Gargoyle\\GargoyleWhat1.wav"
        call PlaySoundPath.execute()
        call MultiboardSetTitleText( udg_SquadStatus, "Evacuate remaining civilians from town areas." )
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Search for Civilians" )
        call QuestSetDescription(udg_CurrentOrders, "Recover the remaining population from the town and provide cover. Isolate and neutralize any infected residents. Extraction for the remaining populace will arrive in 12 minutes." )
        call MissionUpdate.execute()
        call PingMinimapEx(-700.0, -100.0, 10.0, 255, 0, 0, false)
        call ALICEText(5.0, "|cff8b864eNew Objective|r : Search for Remaining Civilians." )
        call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))+0.01*udg_Players)
        call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))+0.01*udg_Players)
        call PolledWait(8.0*udg_Pace)
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Perform a house to house search. We picked up a dozen lifesigns." )
        call PolledWait(20.0*udg_Pace)
        set udg_soundpath = "Units\\Undead\\Gargoyle\\GargoyleWhat2.wav"
        call PlaySoundPath.execute()
        set udg_Visibility = 63
        call IntermissionRestore()
        call StartSound(gg_snd_HoldPosition)
        call PolledWait(5.0*udg_Pace)
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Keep the civilians close." )
        call PolledWait(15.0*udg_Pace)
        call RemoveDestructable(udg_Environment[1])
        call RemoveDestructable(udg_Environment[2])
        call RemoveDestructable(udg_Environment[3])
        if udg_SurveillanceComplete!=5.0 then
            call GeneralText(5.0, "|cffcd950cBattalion|r : Surveillance Network incomplete. Birds are unable to pinpoint the exact location of incoming hostiles." )
        else
            set udg_MissionsCompleted=udg_MissionsCompleted+1
            call GeneralText(5.0, "|cffcd950cBattalion|r : Air support has neutralized pockets of incoming hostiles." )
        endif
        set udg_soundpath = "Units\\Undead\\Gargoyle\\GargoyleWhat3.wav"
        call PlaySoundPath.execute()
        call PolledWait(20.0*udg_Pace)
        call RemoveDestructable(udg_Environment[4])
        call RemoveDestructable(udg_Environment[5])
        call RemoveDestructable(udg_Environment[6])
        if GetRandomInt(1,10)==1 then
            call DisplayTimedTextToPlayer( GetLocalPlayer(), 0.0, 0.0, 1.5, "|cffcd950cCivilian|r : I'm scared..." )
        endif
        call GeneralText(8.0, "|cffcd950cBattalion|r : Find a good defensive position and bunker down. It's too dangerous to extract these civilians by land. We're trying to get us a vessel from the squids." )
        call PolledWait(30.0*udg_Pace)
        if GetWidgetLife(udg_Boss)>0.405 then
            call SetUnitVertexColorBJ( udg_Boss, 40.0, 90.0, 50.0, 0 )
            call PolledWait(2.)
            call FieldChat(udg_Boss, 10.0, "|cffcd950cCivilian|r : I'm feeling sick." )
        endif
        if GetRandomInt(0,50)==1 then
            call GankMarine(Player(13),'n00W',2+udg_Spawn,1800,3500)
            call GankMarine(Player(13),'n00W',2+udg_Spawn,1800,3500)
        endif
        call GankMarine(Player(13),'nzom',2*udg_Spawn,1600,2000)
        call GankMarine(Player(13),'n00M',udg_Spawn,1600,2000)
        call GeneralText(5.0, "|cffcd950cBattalion|r : The USS Independence will arrive at your sector in ten minutes to extract the remaining civilians. How is your situation? Over." )
        call GankMarine(Player(13),'n00M',udg_Spawn,1600,2000)
        call RandomSpawn('ugar',1,GetRandomInt(1, udg_Spawn)) //Gargolye
        call PolledWait(4.)
        call GeneralText(5.0, "|cffcd950cMarine|r : Iron Hand, we're holding well for now. We're going to need more supplies. Over." )
        call RandomSpawn('u00L',4,IMinBJ(5, udg_Spawn)) //Blink
        call PolledWait(4.)
        call GeneralText(5.0, "|cffcd950cBattalion|r : We're arranging that. Keep us updated on your situation. Out." )
        call PolledWait(30.0*udg_Pace)
        call LightningAmbience.execute()
        call RandomSpawn('n002',1,GetRandomInt(1, udg_Spawn)) //Devourer
        call GankMarine(Player(13),'nzom',3*udg_Spawn,1600,2000)
        call RandomSpawn('u000',2,GetRandomInt(0, udg_Spawn)) //Futty
        call RandomSpawn('u00L',4,IMinBJ(5, udg_Players)) //Blink
        call RandomSpawn('ugar',1,GetRandomInt(1, udg_Spawn)) //Gargolye
        call PolledWait(30.0*udg_Pace)
        if udg_Boss!=null and GetWidgetLife(udg_Boss)>0.405 then
            call FieldChat(udg_Boss, 5.0, "|cffcd950cCivilian|r : Argh!" )
            call PolledWait(2.5)
            call KillUnit(udg_Boss)
            call PolledWait(1.25)
            call CreateUnit(Player(14),'n009',GetUnitX(udg_Boss),GetUnitY(udg_Boss),0.0) //Unknown Parasite
        endif
        call RandomSpawn('u00L',4,IMinBJ(5,udg_Players)) //Blink
        call MultiboardSetTitleText( udg_SquadStatus, "Unknown Signatures Detected" )
        call GankMarine(Player(13),'ugar',2*udg_Spawn,1600,2000)
        call GankMarine(Player(13),'n00M',4+udg_Spawn,1600,2000)
        call GeneralText(10.0, "|cffcd950cBattalion|r : Reconnaissance satellites are picking up strange activity." )
        call PolledWait(6.)
        if udg_SquadXP>20000 then
            call RandomSpawn('n016',1,udg_Spawn) //Invi Worm
        endif
        call GeneralText(10.0, "|cffcd950cMarine|r : What do you suppose that means?" )
        call PolledWait(5.)
        set udg_Visibility = 62
        call IntermissionRestore()
        call GeneralText(10.0, "|cffcd950cMarine #2|r : You stupid shit. What do you think it means? There's more Zack coming to chew our asses off." ) 
        call PolledWait(20.0*udg_Pace)
        if udg_Players>0 then
            if GetRandomInt(1,2)==1 then
                //call Wave8b.execute()
                call ExecuteRegisteredFunction("Wave8b")
                        
                //call DestroyTrigger(gg_trg_Moirae_Tracker)
            else
                call ExecuteRegisteredFunction("Wave8a")
                //call Wave8a.execute()
                //call DestroyTrigger(gg_trg_Hades_Snatch)
            endif
        endif
    endfunction


    private function init takes nothing returns nothing

        
        call RegisterFunction("Wave7a", function Wave7a)
        call RegisterFunction("Wave7c", function Wave7c)
    endfunction
    
endlibrary